package cn.st4rlight.util.check;

import org.apache.commons.lang3.BooleanUtils;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author st4rlight <st4rlight@163.com>
 * Created on 2025-05-03
 */
@Data
@AllArgsConstructor
public class SimpleCheckResult {

    // 是否通过校验
    private Boolean passCheck;

    // 校验不通过的原因
    private String rejectReason;


    public boolean hasPassCheck() {
        return BooleanUtils.isTrue(this.passCheck);
    }

    public static SimpleCheckResult pass() {
        return new SimpleCheckResult(true, "");
    }

    public static SimpleCheckResult pass(String passReason) {
        return new SimpleCheckResult(true, passReason);
    }

    public static SimpleCheckResult reject(String rejectReason) {
        return new SimpleCheckResult(false, rejectReason);
    }

    public static SimpleCheckResult reject() {
        return new SimpleCheckResult(false, "");
    }

    public static SimpleCheckResult assertTrue(boolean flag, String errMsg) {
        return flag ? pass() : reject(errMsg);
    }
}
